package com.huawei.appgallery.forum.user.usercenter.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.base.ui.JGWTabFragment;
import com.huawei.appgallery.forum.user.api.IUserFollow;
import com.huawei.appgallery.forum.user.api.IUserFollowProtocol;
import com.huawei.appgallery.forum.user.usercenter.bean.ForumFollowUserCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse.TabInfo;
import com.huawei.appmarket.framework.widget.ExpandScrollLayout;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.List;
import o.bqx;
import o.bsl;
import o.cbb.a;
import o.cbb.j;
import o.cbz;
import o.cha;
import o.chz;
import o.dgp;
import o.fho;
import o.ll;

@FragmentDefine(alias = "forumUserFollowFragment", protocol = IUserFollowProtocol.class)
public class UserFollowFragment extends JGWTabFragment {
    private b ʻˊ;
    private IUserFollow ʻˋ;
    private int ʼˋ;
    private boolean ꜝ;
    private String ﾞ;

    final class b extends BroadcastReceiver {
        final /* synthetic */ UserFollowFragment ˏ;

        private b(UserFollowFragment userFollowFragment) {
            this.ˏ = userFollowFragment;
        }

        public void onReceive(Context context, Intent intent) {
            Intent safeIntent = new SafeIntent(intent);
            Object ˎ = this.ˏ.ʻˋ.ˎ(safeIntent);
            int ॱ = this.ˏ.ʻˋ.ॱ(safeIntent);
            if (!TextUtils.isEmpty(ˎ)) {
                this.ˏ.ॱ(ˎ, ॱ);
            }
        }
    }

    public void ˏ(Bundle bundle) {
        IUserFollowProtocol iUserFollowProtocol = (IUserFollowProtocol) this.ﹳ.ॱ();
        String uri = iUserFollowProtocol.getUri();
        this.ʼˋ = iUserFollowProtocol.getFocus();
        this.ꜝ = iUserFollowProtocol.getIgnoreTitle();
        if (uri != null) {
            int lastIndexOf = uri.lastIndexOf(HiAnalyticsConstant.REPORT_VAL_SEPARATOR);
            if (lastIndexOf >= 0) {
                this.ﾞ = uri.substring(lastIndexOf);
            } else if (ॱˋ() != null) {
                ॱˋ().finish();
                return;
            } else {
                return;
            }
        }
        this.ʼ = new bsl(this, null, uri);
        this.ʻˋ = (IUserFollow) fho.ˏ().ˋ("User").ॱ(IUserFollow.class);
        this.ʻˊ = new b();
        super.ˏ(bundle);
        ॱʾ();
    }

    private static boolean ˋॱ(String str) {
        return str != null && str.startsWith("forum|user_followings");
    }

    private static boolean ˏॱ(String str) {
        return str != null && str.startsWith("forum|user_followers");
    }

    private void ॱʾ() {
        ʻ(a.ˋ);
        if (ˋॱ(this.ʼˊ)) {
            ʼ(j.ˍ);
        } else if (ˏॱ(this.ʼˊ)) {
            ʼ(j.ˋᐝ);
        }
    }

    public ExpandScrollLayout ॱˈ() {
        ExpandScrollLayout ॱˈ = super.ॱˈ();
        if (!(this.ॱـ == null || ॱˊ() == null)) {
            this.ॱـ.setBackgroundColor(ॱˊ().getResources().getColor(o.bqz.b.ˊ));
        }
        return ॱˈ;
    }

    public String ͺˎ() {
        return TextUtils.isEmpty(this.ʼˊ) ? "" : this.ʼˊ.substring(0, this.ʼˊ.lastIndexOf(HiAnalyticsConstant.REPORT_VAL_SEPARATOR) + 1) + System.currentTimeMillis();
    }

    public List<dgp> ॱ(BaseDetailResponse baseDetailResponse) {
        bqx.ˊ("UserFollowFragment", "getTabItemList");
        if (baseDetailResponse == null || baseDetailResponse.ˎ() == null) {
            return null;
        }
        List ˎ = baseDetailResponse.ˎ();
        for (int i = 0; i < ˎ.size(); i++) {
            TabInfo tabInfo = (TabInfo) ˎ.get(i);
            String ʼ = tabInfo.ʼ();
            if (!TextUtils.isEmpty(this.ﾞ)) {
                tabInfo.ˋ(ʼ + this.ﾞ);
            }
            if (i == this.ʼˋ) {
                tabInfo.ˏ("1");
            }
        }
        return ˏ(ˎ, baseDetailResponse.ˋˊ());
    }

    public cha ॱʿ() {
        return new cbz(ॱˋ(), ʽॱ(), this.ᐝʽ);
    }

    private void ॱ(String str, int i) {
        bqx.ˊ("UserFollowFragment", "refreshFollowStatus: " + i);
        Object obj = null;
        for (chz ˏ : this.י.ʻॱ()) {
            Object obj2;
            for (CardBean cardBean : ˏ.ˏ()) {
                if (cardBean instanceof ForumFollowUserCardBean) {
                    User ˊ = ((ForumFollowUserCardBean) cardBean).ˊ();
                    if (ˊ != null && str.equals(ˊ.ॱˋ())) {
                        if (i != ˊ.ʻॱ()) {
                            ˊ(i, ˊ);
                            obj2 = 1;
                            obj = obj2;
                        }
                        obj2 = obj;
                        obj = obj2;
                    }
                }
            }
            obj2 = obj;
            obj = obj2;
        }
        if (obj != null) {
            bqx.ˊ("UserFollowFragment", "provider.onDataChanged#");
            this.י.ˋॱ();
        }
    }

    private void ˊ(int i, User user) {
        user.ˎ(i);
        int ˊॱ = user.ˊॱ();
        if (i == 1 || i == 2) {
            user.ᐝ(ˊॱ + 1);
        } else {
            user.ᐝ(ˊॱ == 0 ? 0 : ˊॱ - 1);
        }
    }

    public void ˋʼ() {
        super.ˋʼ();
        if (ॱˊ() != null) {
            ll.ˏ(ॱˊ()).ˋ(this.ʻˊ);
        }
    }

    public void ˌॱ() {
        super.ˌॱ();
        IntentFilter ˎ = this.ʻˋ.ˎ();
        if (ॱˊ() != null) {
            ll.ˏ(ॱˊ()).ˏ(this.ʻˊ, ˎ);
        }
    }

    public void ˊ(String str) {
        if (!this.ꜝ) {
            ˏ(str);
            ˋʽ();
        }
    }
}
